#pragma once
#include "types.h"
#include <string>
#include <iostream>
#include <memory>
using namespace std;

enum VertexType : uchar
{
	eStatic,
	eAnimated
};
struct StaticVertex
{
	float3 position;
	float3 normal;
	float3 tangent;
	float3 bitangent;
	float2 uv;
};
struct AnimatedVertex : public StaticVertex
{
	uint bones[2];
	float bone_weights[2];
};		
typedef uint Index;
class Geometry
{	
public:
	Geometry(uint vertices_count, uint vertex_stride, uint indexes_count) : 
		m_vertex_stride(vertex_stride), m_vertices_count(vertices_count), m_indexes_count(indexes_count)
	{
		m_vertices = new char[vertex_stride * vertices_count];
		m_indexes = new Index[indexes_count];
	}
	~Geometry()
	{
		delete [] m_vertices;
		delete [] m_indexes;
	}
public:
	char* vertices_pointer()
	{
		return m_vertices;
	}
	Index* indexes_pointer()
	{
		return m_indexes;
	}
	uint vertices_byte_size() 
	{
		return m_vertex_stride * m_vertices_count;
	}
	uint indexes_byte_size() 
	{
		return sizeof(Index) * m_indexes_count;
	}
	uint primitive_count()
	{
		return m_indexes_count / 3;
	}
public:
	uint m_vertex_stride;
	uint m_vertices_count;
	uint m_indexes_count;
private:
	Index* m_indexes;
	char* m_vertices;
};

void serialize_geometry(shared_ptr<Geometry> data, ostream& out);
shared_ptr<Geometry> deserialize_geometry(istream& in);

shared_ptr<Geometry> fullscreen_quad();
shared_ptr<Geometry> triangle();
shared_ptr<Geometry> animated_triangle();	
